<template>
    <div>
        <!-- ComingSoon page is a children of Film -->
        <ul>
            <li v-for="data in comingSoonListGetter" :key="data.filmId" @click="handleClick(data.isPresale, data.filmId)">
                <!-- <li v-for="data in $store.state.comingSoonListState" :key="data.filmId" @click="handleClick(data.filmId)"> -->
                <img :src="data.poster" />
                <div>
                    <h4>
                        {{ data.name }}
                        <span>{{ data.item.name }}</span>
                    </h4>
                    <p v-if="data.grade">
                        观众评分
                        <span>{{ data.grade }}</span>
                    </p>
                    <p>主演：{{ data.actors | actorsFilter }}</p>
                    <p>{{ data.nation }} | {{ data.runtime }}分钟</p>
                </div>
            </li>
        </ul>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { MessageBox } from 'mint-ui';
import { actorsFilterMixin } from '@/mixin';

export default {
    data() {
        return {
            dataList: []
        };
    },
    mounted() {
        if (this.$store.state.comingSoonListState.length === 0) {
            this.$store.dispatch('getComingSongAction');
        } else {
            console.log('获取的store缓存数据，没有发送请求！');
        }
    },
    methods: {
        handleClick(isPresale, filmId) {
            if (!isPresale) {
                MessageBox({
                    title: '提示',
                    message: '该影片还没有排期，请看看其它影片吧?',
                    showCancelButton: true
                }).then(res => {
                    if (res === 'confirm') {
                        this.$router.push('/films');
                    }
                });
            }

            // this.$router.push(`/films/detail/${id}`); // 注意有${}时不能用引号ES6语法
            this.$router.push({
                name: 'Detail',
                params: { filmId: filmId }
            }); // 命名路由，使用name方式调用
        }
    },
    computed: {
        ...mapGetters(['comingSoonListGetter'])
    },
    mixins: [actorsFilterMixin]
};
</script>

<style lang="scss" scoped>
div {
    margin-left: 10px;
    margin-bottom: 40px;
    ul {
        padding: 5px;
        li {
            list-style: none;
            width: 100%;
            height: 105px;
            border-bottom: 1px solid #eeeeee;
            padding-top: 10px;
            cursor: pointer;
            display: flex;
            img {
                width: 66px;
                height: 93px;
                float: left;
            }
            div {
                flex: 1;
                overflow: hidden;
                margin-left: 10px;
                margin-bottom: 0;
                h4 {
                    margin: 0px;
                    padding-top: 8px;
                    font-weight: normal;
                    span {
                        background: #dddddd;
                        font-size: 12px;
                        color: #ffffff;
                    }
                }
                p {
                    font-size: 13px;
                    color: #797d82;
                    margin: 0px;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    span {
                        color: lightsalmon;
                    }
                }
            }
        }
    }
}
</style>
